package com.tianji.aigc.config;

import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.tianji.aigc.ChatMemory.RedisChatMemory;
import com.tianji.aigc.Constants.SystemConstants;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * SpringAI配置类
 *
 * @Author mr.wu
 * @Date 2025-8-17 15:01
 */
@Configuration
public class SpringAiConfig {
    @Bean
    public ChatClient chatClient(DashScopeChatModel dashScopeChatModel, MessageChatMemoryAdvisor chatMemoryAdvisor) {
        return ChatClient
                .builder(dashScopeChatModel)//对话模型对象
                .defaultAdvisors(new SimpleLoggerAdvisor(), //日志记录器
                        chatMemoryAdvisor)//会话记忆器
                .defaultSystem(SystemConstants.SYSTEM)//设置默认系统提示词
                .build();
    }

    @Bean
    public MessageChatMemoryAdvisor chatMemoryAdvisor(RedisChatMemory chatMemory) {
        return new MessageChatMemoryAdvisor(chatMemory);
    }
}
